package ru.st.selenium.pages;


import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;
import org.openqa.selenium.support.ui.Select;

public class AddMoviePage extends InternalPage {

	public AddMoviePage(PageManager pages) {
		super(pages);
	}
	
  @FindBy(name = "name")
	private WebElement TitleField;

  @FindBy(name = "year")
  private WebElement YearField;
  
  
  @FindBy(css="img[alt=\"Save\"]")
  private WebElement submitButton;
  
 
  @FindBy(name = "submit")
  private WebElement submitButton1;
  
  
  @FindBys({ @FindBy (id  = "updateform"),
	  @FindBy(tagName = "tr")})
    private List<WebElement> ReqRef; 
  
  @FindBy (id  = "updateform")
  private WebElement Ref;


  
  public AddMoviePage setFieldTitle(String text) {
	    TitleField.sendKeys(text);
	    return this;
	  }

  public AddMoviePage setFieldYear(String text) {
	    YearField.sendKeys(text);
	    return this;
	  }
  
  public AddMoviePage clickSubmitButton() {
		submitButton.click();
		return this;
	}
  
  public AddMoviePage clickSubmitButton1() {
		submitButton1.click();
		return this;
	}
  
  public AddMoviePage ensurePageLoaded()  {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.className("addmovie")));
	    return this;
	  }
  
  
  public WebElement getRef(int i) {
	 	  
	  
	  return Ref.findElements(By.tagName("tr")).get(i).
			    findElements(By.tagName("td")).get(1).
			    findElement(By.tagName("label"));
  }
  
}